package cn.haulon.express;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * Created by Haulon on 18/09/2017.
 * <p>
 * Used as ...
 */
@SuppressWarnings("WeakerAccess")
public class ExpressManager {
    private static final Map<String, Express> serverMap = new ConcurrentHashMap<>();
    private static final ExpressManager me = new ExpressManager();

    private ExpressManager() {
    }

    public static ExpressManager me() {
        return me;
    }

    public Express get(String key) {
        if (serverMap.containsKey(key)) return serverMap.get(key);
        return null;
    }

    public void put(String key, Express express) {
        if (key == null || key.trim().length() == 0) throw new RuntimeException("server key is null!");
        if (express == null) throw new RuntimeException("express server is null!");
        serverMap.put(key, express);
    }

    @SuppressWarnings("unused")
    public void put(Express express) {
        if (express == null) throw new RuntimeException("express server is null!");
        put(express.getClass().getName(), express);
    }
}
